package com.my.redis;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * Created by 80002023 on 2016/4/25.
 */
public abstract class RedisSupport<K extends Serializable, V> implements IManager<K, V> {

    private final Logger logger = LogManager.getLogger(getClass());

    protected RedisTemplate<K, V> redisTemplate;

    /**
     * 设置redisTemplate
     *
     * @param redisTemplate the redisTemplate to set
     */
    @Resource
    public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    /**
     * 获取 RedisSerializer
     */
    protected RedisSerializer<String> getRedisSerializer() {
        logger.info("RedisSupport getRedisSerializer.");
        return redisTemplate.getStringSerializer();
    }

    public void delete(K key) {
        redisTemplate.delete(key);
    }

    public void delete(List<K> keys) {
        redisTemplate.delete(keys);
    }
}
